import React, { useState } from 'react'
import { AccountContext } from '../../context'
import { Form, Button, ButtonProps } from 'antd'
import './index.less'
interface SubmitProps extends ButtonProps{
    
}
export const Submit = ({ children,...rest }:ButtonProps) => {
  const [loading, setLoading] = useState(false)
  const form = Form.useFormInstance()
  const { onSubmit } = React.useContext(AccountContext)
  const onOk = async () => {
    console.log('onSubmit')
    setLoading(true)
    try {
      const formData = await form.validateFields()

      if (onSubmit) {
        await onSubmit(formData)
      }

    } catch (error) {
      console.error(error)
    }
    setLoading(false)

    // console.log({ form }, )
  }
  return <Button  loading={loading} block type='primary' onClick={onOk}  {...rest}>
    {children}
  </Button>
}